const app = getApp();
const AJAX = app.$ajax,
  $wx = app.$wx;

Page({
  onLoad(options){
    this.setData({
      detailId: options.detail_id
    }, callback => {
      this.getTopicDetail();
    });
  },

  disapprove(){
    this.isLike({ is_like: 2 }, 2);
  },
  
  applaud(){
    this.isLike({ is_like: 1 }, 1);
  },

  getTopicDetail(){
    let td = this.data;
    AJAX.getTopicDetail({
      loadType: 'bar',
      id: td.detailId
    }).then(([status, res, msg]) => {
      if(status){
        this.setData({
          detail: res.details,
          recommendHostList: res.hostlist
        });
      }else{
        $wx.showToast(msg);
      }
    });
  },

  isLike(params = {}, type){
    let _this = this,
        td = this.data;
    params.loadType = 'default';
    params.loadMsg = '加载中...';
    params.id = td.detail.id;

    AJAX.isLike(params).then(([status, res, msg]) => {
      $wx.showToast(msg, {
      success(){
        if(type == 1){
          _this.getTopicDetail();
        }
      }
      });
    });
  }
});